import cv2


class MouseUse(object):

    def __init__(self, window):
        self.__sx = 0
        self.__sy = 0
        self.__ex = 0
        self.__ey = 0
        self.FinishFlag = False
        self.StartFlag = False
        cv2.setMouseCallback(window, self.mouse)

    # mouse callback function
    def mouse(self, event, x, y, flags, param):

        if event == cv2.EVENT_LBUTTONDOWN:
            self.StartFlag = True
            self.__sx, self.__sy = x, y

        elif event == cv2.EVENT_MOUSEMOVE:
            # cv2.rectangle(img, (sx, sy), (x, y), (0, 255, 0), 1)
            self.__ex, self.__ey = x, y
        if event == cv2.EVENT_LBUTTONUP:
            self.FinishFlag = True

    def get_sx(self):
        return self.__sx

    def get_sy(self):
        return self.__sy

    def get_ex(self):
        return self.__ex

    def get_ey(self):
        return self.__ey

    # def get_crop(self, img):
    #     while(1):
    #         cv2.imshow('Display', img)
    #         if self.StartFlag and not self.FinishFlag:
    #             cv2.rectangle(img, (self.__sx, self.__sy), (self.__ex, self.__ey), (0, 255, 0), 1)
    #         elif self.StartFlag and self.FinishFlag:
    #             break
